home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / gtlayout-Source.lha / LT_CreateHandle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-03  |  7.1 KB  |  316 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. LayoutHandle * LIBENT
  10. LT_CreateHandle(REG(a0) struct Screen *Screen,REG(a1) struct TextAttr *Font)
  11. {
  12.     return(LT_CreateHandleTags(Screen,
  13.         LH_Font,    Font,
  14.     TAG_DONE));
  15. }
  16.  
  17.  
  18. /*****************************************************************************/
  19.  
  20.  
  21. LayoutHandle * __stdargs
  22. LT_CreateHandleTags(struct Screen *Screen,...)
  23. {
  24.     LayoutHandle    *Handle;
  25.     va_list      VarArgs;
  26.  
  27.     va_start(VarArgs,Screen);
  28.     Handle = LT_CreateHandleTagList(Screen,(struct TagItem *)VarArgs);
  29.     va_end(VarArgs);
  30.  
  31.     return(Handle);
  32. }
  33.  
  34.  
  35. /*****************************************************************************/
  36.  
  37.  
  38. LayoutHandle * LIBENT
  39. LT_CreateHandleTagList(REG(a0) struct Screen *Screen,REG(a1) struct TagItem *TagList)
  40. {
  41.     LayoutHandle    *Handle;
  42.     struct Screen    *PubScreen;
  43.     APTR         Pool;
  44.  
  45. #ifdef DO_PICKSHORTCUTS
  46.     ObtainSemaphore(<P_KeySemaphore);
  47.  
  48.     if(!LTP_KeysInitialized)
  49.     {
  50.         UBYTE          mapBuffer[2 * 3];
  51.         UBYTE          remapBuffer[10];
  52.         LONG          i;
  53.         struct InputEvent event;
  54.  
  55.         for(i = 0 ; i < 256; i++)
  56.         {
  57.             if((i > ' ' && i < 127) || i > 160)
  58.             {
  59.                 remapBuffer[0] = i;
  60.                 remapBuffer[1] = 0;
  61.  
  62.                 if(MapANSI(remapBuffer,1,mapBuffer,3,NULL) == 1)
  63.                 {
  64.                     if(!(mapBuffer[1] & ~QUALIFIER_SHIFT))
  65.                     {
  66.                         event . ie_NextEvent        = NULL;
  67.                         event . ie_Class        = IECLASS_RAWKEY;
  68.                         event . ie_SubClass        = 0;
  69.                         event . ie_Code         = mapBuffer[0];
  70.                         event . ie_Qualifier        = mapBuffer[1] & ~QUALIFIER_SHIFT;
  71.                         event . ie_position . ie_addr    = NULL;
  72.  
  73.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  74.                             LTP_Keys[0][i] = remapBuffer[0];
  75.  
  76.                         event . ie_NextEvent        = NULL;
  77.                         event . ie_Class        = IECLASS_RAWKEY;
  78.                         event . ie_SubClass        = 0;
  79.                         event . ie_Code         = mapBuffer[0];
  80.                         event . ie_Qualifier        = mapBuffer[1] | QUALIFIER_SHIFT;
  81.                         event . ie_position . ie_addr    = NULL;
  82.  
  83.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  84.                             LTP_Keys[1][i] = remapBuffer[0];
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.  
  90.         LTP_KeysInitialized = TRUE;
  91.     }
  92.  
  93.     ReleaseSemaphore(<P_KeySemaphore);
  94. #endif    /* DO_PICKSHORTCUTS */
  95.  
  96.     if(!Screen)
  97.     {
  98.         if(!(PubScreen = LockPubScreen(NULL)))
  99.             return(NULL);
  100.         else
  101.             Screen = PubScreen;
  102.     }
  103.     else
  104.         PubScreen = NULL;
  105.  
  106.     if(Pool = AsmCreatePool(MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR,1024,1024,SysBase))
  107.     {
  108.         if(Handle = AsmAllocPooled(Pool,sizeof(LayoutHandle),SysBase))
  109.         {
  110.             struct TagItem    *List,
  111.                     *Entry;
  112.             BOOLEAN         MenuGlyphs;
  113.  
  114.             MenuGlyphs = FALSE;
  115.  
  116.             Handle -> Pool            = Pool;
  117.             Handle -> Screen        = Screen;
  118.             Handle -> InitialTextAttr    = Screen -> Font;
  119.             Handle -> PubScreen        = PubScreen;
  120.             Handle -> PointBack        = Handle;
  121.             Handle -> GroupID        = PHANTOM_GROUP_ID;
  122.  
  123.             Handle -> ExitFlush        = TRUE;
  124.             Handle -> RawKeyFilter        = TRUE;
  125. #ifdef DO_CLONING
  126.             Handle -> CloningPermitted    = TRUE;
  127. #endif
  128.             List = TagList;
  129.  
  130.             while(Entry = NextTagItem(&List))
  131.             {
  132.                 switch(Entry -> ti_Tag)
  133.                 {
  134.                     case LH_Font:
  135.  
  136.                         Handle -> InitialTextAttr = (struct TextAttr *)Entry -> ti_Data;
  137.                         break;
  138.  
  139.                     case LH_MenuGlyphs:
  140.  
  141.                         MenuGlyphs = Entry -> ti_Data;
  142.                         break;
  143.  
  144.                     case LH_Parent:
  145.  
  146.                         Handle -> Parent = (struct Window *)Entry -> ti_Data;
  147.                         break;
  148.  
  149.                     case LH_BlockParent:
  150.  
  151.                         Handle -> BlockParent = Entry -> ti_Data;
  152.                         break;
  153.  
  154.                     case LH_ExitFlush:
  155.  
  156.                         Handle -> ExitFlush = Entry -> ti_Data;
  157.                         break;
  158.  
  159.                     case LH_UserData:
  160.  
  161.                         Handle -> UserData = (APTR)Entry -> ti_Data;
  162.                         break;
  163.  
  164.                     case LH_RawKeyFilter:
  165.  
  166.                         Handle -> RawKeyFilter = Entry -> ti_Data;
  167.                         break;
  168.  
  169.                     case LH_AutoActivate:
  170.  
  171.                         Handle -> AutoActivate = Entry -> ti_Data;
  172.                         break;
  173.  
  174.                     case LH_LocaleHook:
  175.  
  176.                         Handle -> LocaleHook = (struct Hook *)Entry -> ti_Data;
  177.                         break;
  178.  
  179.                     case LH_EditHook:
  180.  
  181.                         Handle -> StandardEditHook = (struct Hook *)Entry -> ti_Data;
  182.                         break;
  183. #ifdef DO_CLONING
  184.                     case LH_CloningPermitted:
  185.  
  186.                         Handle -> CloningPermitted = Entry -> ti_Data;
  187.                         break;
  188.  
  189.                     case LH_SimpleClone:
  190.  
  191.                         if(Handle -> SimpleClone = Entry -> ti_Data)
  192.                             Handle -> ExactClone = FALSE;
  193.  
  194.                         break;
  195.  
  196.                     case LH_ExactClone:
  197.  
  198.                         if(Handle -> ExactClone = Entry -> ti_Data)
  199.                             Handle -> SimpleClone = FALSE;
  200.  
  201.                         break;
  202. #endif
  203.                 }
  204.             }
  205.  
  206. #ifdef DO_FRACTION_KIND
  207.             Handle -> FracEditHook . h_Entry    = (HOOKFUNC)LTP_FracEditRoutine;
  208.             Handle -> FracEditHook . h_Data     = Handle;
  209. #endif
  210.  
  211. #ifdef DO_PASSWORD_KIND
  212.             Handle -> PasswordEditHook . h_Entry    = (HOOKFUNC)LTP_PasswordEditRoutine;
  213.             Handle -> PasswordEditHook . h_Data    = Handle;
  214. #endif
  215.  
  216.             Handle -> DefaultEditHook . h_Entry    = (HOOKFUNC)LTP_DefaultEditRoutine;
  217.             Handle -> DefaultEditHook . h_Data    = Handle;
  218.  
  219.             Handle -> BackfillHook . h_Entry    = (HOOKFUNC)LTP_BackfillRoutine;
  220.             Handle -> BackfillHook . h_Data     = Handle;
  221.  
  222. #ifdef DO_HEXHOOK
  223.             Handle -> HexEditHook . h_Entry     = (HOOKFUNC)LTP_HexEditRoutine;
  224.             Handle -> HexEditHook . h_Data        = Handle;
  225. #endif
  226.  
  227.             if(Handle -> DrawInfo = GetScreenDrawInfo(Screen))
  228.             {
  229.                 LONG i;
  230.  
  231.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  232.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  233.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  234.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  235.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  236.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  237.  
  238.                 if(V39 && MenuGlyphs)
  239.                 {
  240.                     LONG Size,FontHeight = Handle -> DrawInfo -> dri_Font -> tf_Baseline + 2;
  241.  
  242.                     if(Screen -> Flags & SCREENHIRES)
  243.                         Size = SYSISIZE_MEDRES;
  244.                     else
  245.                         Size = SYSISIZE_LOWRES;
  246.  
  247.                     if(Handle -> AmigaGlyph = NewObject(NULL,SYSICLASS,
  248.                         SYSIA_DrawInfo, Handle -> DrawInfo,
  249.                         SYSIA_Size,    Size,
  250.                         SYSIA_Which,    AMIGAKEY,
  251.                         IA_Left,    0,
  252.                         IA_Top,     0,
  253.                         IA_Width,    (FontHeight * 3 * Handle -> AspectY) / (2 * Handle -> AspectX),
  254.                         IA_Height,    FontHeight,
  255.                     TAG_DONE))
  256.                     {
  257.                         if(!(Handle -> CheckGlyph = NewObject(NULL,SYSICLASS,
  258.                             SYSIA_DrawInfo, Handle -> DrawInfo,
  259.                             SYSIA_Size,    Size,
  260.                             SYSIA_Which,    MENUCHECK,
  261.                             IA_Left,    0,
  262.                             IA_Top,     0,
  263.                             IA_Width,    (FontHeight * Handle -> AspectY) / Handle -> AspectX,
  264.                             IA_Height,    FontHeight,
  265.                         TAG_DONE)))
  266.                         {
  267.                             DisposeObject(Handle -> AmigaGlyph);
  268.  
  269.                             Handle -> AmigaGlyph = NULL;
  270.                         }
  271.                     }
  272.                 }
  273.  
  274.                 for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  275.                 {
  276.                     if(Handle -> DrawInfo -> dri_Pens[i] > Handle -> MaxPen)
  277.                         Handle -> MaxPen = Handle -> DrawInfo -> dri_Pens[i];
  278.                 }
  279.  
  280.                 if(Handle -> VisualInfo = GetVisualInfoA(Screen,NULL))
  281.                 {
  282.                     InitRastPort(&Handle -> RPort);
  283.  
  284.                     if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
  285.                     {
  286. #ifdef DO_PICKSHORTCUTS
  287.                         memset(Handle -> Keys,TRUE,256);
  288.  
  289.                         for(i = 0 ; i < 256 ; i++)
  290.                         {
  291.                             if(i != 32 && i != 160)
  292.                             {
  293.                                 if(LTP_Keys[0][i])
  294.                                     Handle -> Keys[LTP_Keys[0][i]] = FALSE;
  295.  
  296.                                 if(LTP_Keys[1][i])
  297.                                     Handle -> Keys[LTP_Keys[1][i]] = FALSE;
  298.                             }
  299.                         }
  300. #endif
  301.                         return(Handle);
  302.                     }
  303.                 }
  304.             }
  305.  
  306.             LT_DeleteHandle(Handle);
  307.         }
  308.         else
  309.             AsmDeletePool(Pool,SysBase);
  310.     }
  311.     else
  312.         UnlockPubScreen(NULL,PubScreen);
  313.  
  314.     return(NULL);
  315. }
  316.